package net.office.service.impl;

import net.office.bean.StaffMail;
import net.office.bean.StaffMailExample;
import net.office.mapper.StaffMailMapper;
import net.office.service.LoginService;
import net.office.service.StaffMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StaffMailServiceImpl implements StaffMailService {

    @Autowired
    private StaffMailMapper staffMailMapper;

    @Override
    public List<StaffMail> findAll() {
        StaffMailExample example = new StaffMailExample();
        return staffMailMapper.selectByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer staffMailId) {
        return staffMailMapper.deleteByPrimaryKey(staffMailId);
    }

    @Override
    public List<StaffMail> findByStaffMail(StaffMail staffMail) {
        StaffMailExample example = new StaffMailExample();
        StaffMailExample.Criteria criteria = example.createCriteria();

        if(staffMail.getStaffMailId() != null){
            criteria.andStaffMailIdEqualTo(staffMail.getStaffMailId());
        }
        if(staffMail.getStaffId() != null){
            criteria.andStaffIdEqualTo(staffMail.getStaffId());
        }
        if(staffMail.getStaffNo() != null
                && staffMail.getStaffNo().trim().length() != 0){
            criteria.andStaffNoLike("%" + staffMail.getStaffNo() + "%");
        }
        if(staffMail.getStaffName() != null
                && staffMail.getStaffName().trim().length() != 0){
            criteria.andStaffNameLike("%" + staffMail.getStaffName() + "%");
        }
        if(staffMail.getStaffDepartment() != null
                && staffMail.getStaffDepartment().trim().length() != 0){
            criteria.andStaffDepartmentLike("%" + staffMail.getStaffDepartment() + "%");
        }
        if(staffMail.getStaffPost() != null
                && staffMail.getStaffPost().trim().length() != 0){
            criteria.andStaffPostLike("%" + staffMail.getStaffPost() + "%");
        }
        if(staffMail.getStaffMailPhone() != null
                && staffMail.getStaffMailPhone().trim().length() != 0){
            criteria.andStaffMailPhoneLike("%" + staffMail.getStaffMailPhone() + "%");
        }
        if(staffMail.getStaffMailEmail() != null
                && staffMail.getStaffMailEmail().trim().length() != 0){
            criteria.andStaffMailEmailLike("%" + staffMail.getStaffMailEmail() + "%");
        }
        if(staffMail.getStaffMailAddr() != null
                && staffMail.getStaffMailAddr().trim().length() != 0){
            criteria.andStaffMailAddrLike("%" + staffMail.getStaffMailAddr() + "%");
        }

        example.or(criteria);

        return staffMailMapper.selectByExample(example);
    }

    @Override
    public int insert(StaffMail staffMail) {
        return staffMailMapper.insertSelective(staffMail);
    }

    @Override
    public StaffMail findOneByStaffMailId(Integer staffMailId) {
        return staffMailMapper.selectByPrimaryKey(staffMailId);
    }

    @Override
    public int updateByPrimaryKey(StaffMail staffMail) {
        return staffMailMapper.updateByPrimaryKey(staffMail);
    }
}
